package UILayer;

import ModelLayer.*;
import ControllerLayer.*;
/**
 * Class responsible for the main interface.
 * Will require a employeenumber and password to unlock it's functionality.
 * 
 * @author Anders A.P., Mie P., Anna K., Jakob K., Danny P.
 * @version 1.0
 */
public class MainUI {

    private OrderUI orderUI;
    private ItemUI itemUI;
    private CustomerUI customerUI;
    private EmployeeUI employeeUI;
    private EmployeeCtr employeeCtr;
    private InputDialog inputDialog;
    
    /**
     * Constructor for objects of class MainUI
     */
    public MainUI() {

        orderUI = new OrderUI();
        itemUI = new ItemUI();
        customerUI = new CustomerUI();
        employeeUI = new EmployeeUI();
        employeeCtr = new EmployeeCtr();
        inputDialog = new InputDialog();

    }

    /**
     * Method for logging into the system. Requires a valid employeenumber and password.
     */
    public void startLogIn() {

        boolean succes = false;
        while(!succes) {
            try {
                Employee e = employeeCtr.getEmployee(inputDialog.inputInt("Indtast medarbejdernr.: "));
                if(inputDialog.inputString("Indtast kodeord: ").equals(e.getPassword())) {
                    employeeCtr.setCurrentEmployee(e);
                    start();
                    succes = true;
                }
                else {
                    System.out.println("Kodeord og brugernavn matcher ikke!");
                }
            }
            catch(Exception e) {
                System.out.println("Medarbejder ikke fundet!");
            }
        }

    }
    
    /**
     * Method for creating the main UI and accessing the other UI's, without a password and employee ID.
     */
    public void start() {

        boolean goOn = true;
        MenuList<Integer> m1 = new MenuList<Integer>("\fHoved menu: ", "\nVælg: ");
        m1.addOption("1", "Håndter ordre og tilbud", 1);
        m1.addOption("2", "Håndter kunde", 2);
        m1.addOption("3", "Håndter vare", 3);
        m1.addOption("4", "Håndter medarbejder", 4);
        m1.addOption("0", "Exit", 0);
        
        while(goOn) {
            Integer choice = m1.display();
            switch(choice) {
                case 0:
                    goOn = false;
                    System.out.println("Programmet lukkes ned.");
                    break;
                case 1:
                    orderUI.startOrderUI();
                    break;
                case 2: 
                    customerUI.startCustomerUI();
                    break;                
                case 3:
                    itemUI.startItemUI();
                    break;                
                case 4: 
                    employeeUI.startEmployeeUI();
                    break;                
                default:
                    System.out.println("Input ikke genkendt");
                    break;
            }
        }

    }

}